<template>
	<view class="padb20">
		<stop isBack>
			<view slot="content">设备报修</view>
		</stop>
		<view class="lh2 bcf pad2 bdtso mart3">
			
				<machine-picker v-model="en.machine"></machine-picker>
	<!-- 		<view class="list-style-2 flrc ">
				<view class="flex1">选择设备</view>
				<view class="cu-btn line-green sm round" @click="showSelected = !showSelected" >{{showSelected?'隐藏':'选择'}}</view>
			</view>
			<view class="martb2 flrc lh2 padt5" v-show="showSelected">
				<view class="wh30-30 flcc bdso round3 marr10 pos-r" @tap="scanMachine">
					<view class="cuIcon cuIcon-scan fs24 mart5"></view>
					<view class="mart2">扫码选择</view>
					<ripple></ripple>
				</view>
				<view class="wh30-30 flcc bdso round3 pos-r" @tap="showSelect">
					<view class="cuIcon cuIcon-list fs24 mart5"></view>
					<view class="mart2">列表选择</view>
					<ripple></ripple>
				</view>
			</view>
			<view class="flrc pad3 bdso bc13 mart3" @tap="showSelected = !showSelected"  v-if="isbool(en.machine)">
				<machine-item class="w100" v-model="en.machine" :itemId="selectedMachine.id" :code.sync="selectedMachine.code"></machine-item>
			</view> -->
		</view>
		<view class="lh2 bcf pad2 mart3">
			<sentity label="故障类别" model="MachineBreakCategory" placeholder="请选择" v-model="en.category"></sentity>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<sentity label="故障等级" model="MachineBreakLevel" placeholder="请选择" v-model="en.level"></sentity>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<sentity label="紧急程度" model="MachineBreakEmergency" placeholder="请选择" v-model="en.emergency"></sentity>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<sdatetime label="发现时间" placeholder="请选择首次发现故障的时间" v-model="en.findAt"></sdatetime>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<sswitch label="需要停机" placeholder="请选择" v-model="en.needStop"></sswitch>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<stextarea label="故障描述" placeholder="简单描述故障情况" v-model="en.info"></stextarea>
		</view>
		
		<view class="lh2 bcf pad2 mart3">
			<stext label="联系人姓名" placeholder="[ 可选 ] 请填写联系人姓名" v-model="en.contactName"></stext>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<stext label="联系人手机" placeholder="[ 可选 ] 请填写联系人手机" v-model="en.contactPhone"></stext>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<spics label="附件" placeholder="[ 可选 ] 故障照片" v-model="en.pic"></spics>
		</view>
		<view class="lh2 bcf pad2 bdtso pos-f l0 r0 b0">
			<view class="tac pad2 line-green round cu-btn lg w100 mart5" @tap="submit">
				<view>提交</view>
				<ripple></ripple>
			</view>
		</view>
		<!-- <loading :loading="myIsLoading"></loading> -->
	<!-- 	<view v-if="showSelectList">
			<machine-selector :show="showSelectList" @onSelect="selectMachine" ></machine-selector>
		</view> -->
	</view>
</template>

<script>
	import machineItem from '../../templete/machine/machine_item.vue'
	import machineSelector from '../../templete/machine/machine_selector.vue'
	// import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	// import MescrollCompMixin from "@/components/mescroll-uni/mixins/mescroll-comp.js";
	import machinePicker from '../../templete/machine/machine_picker.vue'
	export default {
		// mixins:[MescrollCompMixin],
		// components:{machineItem,machineSelector},
		components:{machinePicker},
		data() {
			return {
				id:"",
					// showSelectList:true,
					// showSelected:true,
					// selectedMachine:{
					// 	id:'',
					// 	code:'',
					// 	iri:''
					// },
				en:{
					machine:'',
					category:'',
					level:'',
					emergency:'',
					needStop:false,
					info:'',
					contactName:'',
					contactPhone:'',
					pic:[],
				}
			}
		},
		methods: {
			showSelect(){
				this.showSelectList = Math.random()
			},
			selectMachine(val){
				this.log(val)
				this.en.machine=val
				// this.selectedMachine.iri=val
			},
			scanMachine(){
				this.$dev.scan(info=>{
					this.log(info)
					this.selectedMachine.code = info
				},(err)=>{
						this.log(err)
				})
			},
			submit(){
				this.log(this.en)
				//检查数据
				// machine:'',
				// category:'',
				// level:'',
				// emergency:'',
				// needStop:false,
				// info:'',
				// contactName:'',
				// contactPhone:'',
				// pics:[],
				if(this.isnull(this.en.machine)){this.$com.showToast('请选择设备');return;}
				if(this.isnull(this.en.category)){this.$com.showToast('请选择故障类别');return;}
				if(this.isnull(this.en.level)){this.$com.showToast('请选择故障等级');return;}
				if(this.isnull(this.en.emergency)){this.$com.showToast('请选择紧急程度');return;}
				if(this.isnull(this.en.info)){this.$com.showToast('请简单说明故障情况');return;}
				this.$api.put("/api/machineBreaks",this.en,(res)=>{
					this.log(res)
					if(res.s == 1){
						this.goback()
					}
				})
			}
		},
		onLoad(option) {
			this.clearLoading()
			this.id = option.id
			if(this.isbool(this.id)){
				this.$api.res("machine_breaks",this.id,res=>{
					this.en = res
				})
			}
			if(this.isbool(option.machine)){
				setTimeout(()=>{
					this.en.machine = unescape(option.machine)
				})
			}
			
		}
	}
</script>

<style>

</style>
